// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets;

import java.nio.ByteBuffer;
import zombie.characters.IsoPlayer;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;

public class PlayerVariables implements INetworkPacket {
    byte count = 0;
    PlayerVariables.NetworkPlayerVariable[] variables = new PlayerVariables.NetworkPlayerVariable[2];

    public PlayerVariables() {
        for (byte _byte = 0; _byte < this.variables.length; _byte++) {
            this.variables[_byte] = new PlayerVariables.NetworkPlayerVariable();
        }
    }

    public void set(IsoPlayer player) {
        String string = player.getActionStateName();
        if (string.equals("idle")) {
            this.variables[0].set(player, PlayerVariables.NetworkPlayerVariableIDs.IdleSpeed);
            this.count = 1;
        } else if (string.equals("maskingleft")
            || string.equals("maskingright")
            || string.equals("movement")
            || string.equals("run")
            || string.equals("sprint")) {
            this.variables[0].set(player, PlayerVariables.NetworkPlayerVariableIDs.WalkInjury);
            this.variables[1].set(player, PlayerVariables.NetworkPlayerVariableIDs.WalkSpeed);
            this.count = 2;
        }
    }

    public void apply(IsoPlayer player) {
        for (byte _byte = 0; _byte < this.count; _byte++) {
            player.setVariable(this.variables[_byte].id.name(), this.variables[_byte].value);
        }
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.count = b.get();

        for (byte _byte = 0; _byte < this.count; _byte++) {
            this.variables[_byte].id = PlayerVariables.NetworkPlayerVariableIDs.values()[b.get()];
            this.variables[_byte].value = b.getFloat();
        }
    }

    @Override
    public void write(ByteBufferWriter b) {
        b.putByte(this.count);

        for (byte _byte = 0; _byte < this.count; _byte++) {
            b.putByte((byte)this.variables[_byte].id.ordinal());
            b.putFloat(this.variables[_byte].value);
        }
    }

    @Override
    public int getPacketSizeBytes() {
        return 1 + this.count * 5;
    }

    @Override
    public String getDescription() {
        String string = "PlayerVariables: ";
        string = string + "count=" + this.count + " | ";

        for (byte _byte = 0; _byte < this.count; _byte++) {
            string = string + "id=" + this.variables[_byte].id.name() + ", ";
            string = string + "value=" + this.variables[_byte].value + " | ";
        }

        return string;
    }

    public void copy(PlayerVariables vars) {
        this.count = vars.count;

        for (byte _byte = 0; _byte < this.count; _byte++) {
            this.variables[_byte].id = vars.variables[_byte].id;
            this.variables[_byte].value = vars.variables[_byte].value;
        }
    }

    private class NetworkPlayerVariable {
        PlayerVariables.NetworkPlayerVariableIDs id;
        float value;

        public void set(IsoPlayer isoPlayer, PlayerVariables.NetworkPlayerVariableIDs networkPlayerVariableIDs) {
            this.id = networkPlayerVariableIDs;
            this.value = isoPlayer.getVariableFloat(networkPlayerVariableIDs.name(), 0.0F);
        }
    }

    private static enum NetworkPlayerVariableIDs {
        IdleSpeed,
        WalkInjury,
        WalkSpeed,
        DeltaX,
        DeltaY,
        AttackVariationX,
        AttackVariationY,
        targetDist,
        autoShootVarX,
        autoShootVarY,
        recoilVarX,
        recoilVarY,
        ShoveAimX,
        ShoveAimY;
    }
}
